Yacon.util.Container = function()
{
	this.fAttributes    =  new Yacon.util.Container.Record();	
}

Yacon.util.Container.Extend(Yacon.util.LinkList,
{
	createRecord :function()
	{
		this.insert("last",null,new Yacon.util.Container.Record());
	},
	getAttrValue:function(attrName)
	{
		return this.fAttributes.getFieldValue(attrName);
	},
	setAttrValue:function(attrName,attrValue)
	{
		this.fAttributes.setFieldValue(attrName,attrValue);
	},
	getFieldValue:function(fieldName)
	{
		if(this.activeElement)
			return this.activeElement.getFieldValue(fieldName);
		else
			return "";
	},
	setJsonStr :function(jsonStr)
	{
		if (Yacon.isEmpty(jsonStr))
			return;
		try{
			var obj = eval(jsonStr);
			if (obj.attr)
				this.fAttributes.jsonList = obj.attr;
			
			if (obj.fields)
			{
				for(var i=0;i<obj.fields.length;i++)
				{
					this.createRecord();
					this.activeElement.jsonList = obj.fields[i];
				}
			}
			this.beforeFirst();
		}catch(e)
		{}
	},
	free: function()
	{
		this.fAttributes.free();
		this.clear();
	}
});


Yacon.util.Container.Record = function()
{
	this.fieldNames    =  new Array();
	this.fieldList     =  new Array();
	this.jsonList      =  null;
	this.factvieField  =  null;
}
Yacon.util.Container.Record.Extend(Object,{
	
	addField :function(field)
	{
		if (Yacon.isEmpty(field))
			return;
		
		if (Yacon.isEmpty(field.getFieldName()))
			return;
		
		var index = this.fieldNames.indexOf(field.getFieldName().toLowerCase());
	    if (index>-1)
		{
			field.setRecord(this);
			this.fieldList[index] = field;
		}else
		{
			 field.setRecord(this);			 
			this.fieldNames.add(field.getFieldName().toLowerCase());
			this.fieldList.add(field);
		}
	    this.factvieField = field;
	},
	getField: function(fieldIndex)
	{
		if (Yacon.isEmpty(fieldIndex))
			return this.factvieField;
		else
			this.factvieField = null;
		
		if (Yacon.isNumber(fieldIndex))
		{
			this.factvieField = this.fieldList.get(fieldIndex);
			 
	    }else  if (Yacon.isString(fieldIndex))
	    {
	    	var index = this.fieldNames.indexOf(fieldIndex.toLowerCase());
		    if (index>-1)
			{
		    	this.factvieField = this.fieldList.get(index);
			}
	    }
		return this.factvieField;	
	},
	getFieldValue: function(fieldIndex)
	{
		if (this.getField(fieldIndex) == null)
		{
			var fieldValue = "";
			if (this.jsonList != null && Yacon.isString(fieldIndex))
				fieldValue = this.jsonList[fieldIndex];
			
			if (fieldValue == null)
				fieldValue = "";
			return fieldValue;
			
		}else
		{
			return this.factvieField.getFieldValue();
		}
	},
	setFieldValue: function(fieldName,fieldValue)
	{
		if (this.getField(fieldName) == null)
			this.creatField(fieldName,fieldValue);
		else
			this.factvieField.setFieldValue(fieldValue);
	},
	creatField: function(fieldName,fieldValue)
	{
		if (Yacon.isEmpty(fieldName))
			return null;
		
		this.factvieField = new Yacon.util.Container.Field();
		this.factvieField.setFieldName(fieldName);
		this.factvieField.setFieldValue(fieldValue);
		this.addField(this.factvieField);
		return this.factvieField;
	},	
	free: function()
	{
		this.fieldNames.clear();
		this.fieldList.clear();
	}	
});

Yacon.util.Container.Field = function()
{
	this.fFieldName    = "";
	this.fFieldValue   = "";
	this.fRecord       = null;
}

Yacon.util.Container.Field.Extend(Object,{
	
	getFieldName :function()
	{
		return this.fFieldName;
	},
	setFieldName:function(fieldName)
	{
		if(fieldName)
			this.fFieldName = fieldName;
	},
	getFieldValue:function()
	{
		return this.fFieldValue + "";
	},
	setFieldValue:function(fieldValue)
	{
		this.fFieldValue = fieldValue;
	},
	getRecord:function()
	{
		return this.fRecord;
	},
	setRecord:function(record)
	{
		this.fRecord = record;
	}
});
